local ma__weishi = fk.CreateSkill{
  name = "ma__weishi",
}

Fk:loadTranslationTable{
  ["ma__weishi"] = "委势",
  [":ma__weishi"] = "出牌阶段限两次，你可以判定，然后将一张与结果花色相同的手牌当【决斗】使用（无则跳过）。<br>"..
  "若你未以此法造成伤害，你重铸所有手牌并回复1点体力。",

  ["#ma__weishi"] = "委势：判定并将同花色手牌当【决斗】使用，未造成伤害则重铸手牌",
  ["#ma__weishi-choose"] = "委势：将一张%arg花色的手牌当【决斗】使用",
  ["@@ma__weishi-inarea"] = "委势",

  ["$ma__weishi1"] = "",
  ["$ma__weishi2"] = "",
}

ma__weishi:addEffect("active", {
  anim_type = "drawcard",
  card_num = 0,
  target_num = 0,
  prompt = "#ma__weishi",
  max_phase_use_time = 2,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    local judge = {
      who = player,
      reason = ma__weishi.name,
      pattern = ".",
    }
    room:judge(judge)
    if table.find(player:getCardIds("h"), function (id)
      return Fk:getCardById(id):compareSuitWith(judge.card)
      end) then
      local cards = table.filter(player:getCardIds("h"), function (id)
      return Fk:getCardById(id).suit == judge.card.suit
      end)
      if #cards > 0 then
        local use = room:askToUseVirtualCard(player, {
          name = {"duel"},
          skill_name = ma__weishi.name,
          prompt = "#ma__weishi-choose:::"..judge.card:getSuitString(true),
          cancelable = false ,
          card_filter = {
          n = 1,
          cards = cards
        },
        skip = false ,
        })
        if use then
          if (not player.dead and use.damageDealt and use.damageDealt[player] or
          not player.dead and not use.damageDealt) then
            room:recastCard(player:getCardIds("h"), player, ma__weishi.name)
            if player:isWounded() then
            room:recover{
            who = player,
            num = 1,
            recoverBy = player,
            skill_name = ma__weishi.name,
            }
            else
            room:obtainCard(player, judge.card, true, fk.ReasonJustMove, player, ma__weishi.name)
            end
          end
        end
      end
    else room:recastCard(player:getCardIds("h"), player, ma__weishi.name)
      if player:isWounded() then
        room:recover{
        who = player,
        num = 1,
        recoverBy = player,
        skill_name = ma__weishi.name,
        }
      end
    end
  end
})

return ma__weishi
